<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="model.Thanhvienmodel"%>

<%@page import="javax.servlet.jsp.tagext.TryCatchFinally"%>
<%@page import="dao.Thanhviendao"%><html>
<head>
<script type="text/javascript">

	function updateThanhVien() {
		
		document.getElementById("actionType").value = "updateThanhVien";
		if (confirm("Ban co chac muon cap nhat dong chi nay khong")) {		
			document.forms["frmThanhVien"].submit();
		}
		
	} 
	
	function Batloi(){
	TXTdn=document.getElementById("txttdn").value;
	TXTmk=document.getElementById("txtmk").value;
	TXTvt=document.getElementById("txtvt").value;
	TXTgc=document.getElementById("txtgc").value;
	
	alert(TXTdn);
	
	if(TXTdn =="" || TXTmk =="" || TXTvt =="" || TXTgc =="" ){
		alert("cac thong tin khong duoc de trong");
		return false;
	}
	else{
		TXTvt=document.getElementById("txtvt");
		KTvt=/[0-9][0-9]*/;
		if(KTvt.test(TXTvt.value)==false){
			alert("Vai tro phai la so");
			return false;
		}
		else{
			return true;
		}
	}	
}
</script>
<style type="text/css">
.canhphai{float:right;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>

<body>
<h1 align="center">Them moi thanh vien</h1>
<form name="frmThanhVien" id="frmThanhVien" action="thanhviencontroller" method="post" onsubmit="return Batloi();">
<table bgcolor="0099ff" align="center">
<% 
	Thanhvienmodel model=null;
	Thanhvienmodel updateModel = null;
	// Xu ly truong hop Update
	String idSelected = new String();
	try {
		idSelected = request.getParameter("updateID");
		updateModel = Thanhviendao.getThanhVienByID(idSelected);
	} catch(Exception e) {
		idSelected = new String();
	}
	
	
	
%>
<tr><td>ID<input type="text" name="txtid" id="txtid" class="canhphai" readonly="readonly" value="<%
	if(model!=null){
		out.println(model.getID());
	}
	if (updateModel != null) {
		out.println(updateModel.getID());
	}
 %>"></input></td></tr>
<tr><td>Ten dang nhap<input  type="text" name="txttdn" id="txttdn" class="canhphai" value="<%
	if(model!=null){
		out.println(model.getTENDN());
	}
	if (updateModel != null) {
		out.println(updateModel.getTENDN());		
	}
 %>
"
<%
	if (updateModel != null) {
		out.println("readonly");		
	}
 %>
></input></td></tr>
<tr><td>Mat khau<input type="password" name="txtmk" id="txtmk" class="canhphai" value="<%
		if(model!=null){
			out.println(model.getMATKHAU());
		}
		if (updateModel != null) {
			out.println(updateModel.getMATKHAU());
	}
	 %>
"></input></td></tr>
<tr><td>Vai tro<input type="text" name="txtvt" id ="txtvt" class="canhphai" value="<%
		if(model!=null){
			out.println(model.getVAITRO());
		}
		if (updateModel != null) {
			out.println(updateModel.getVAITRO());
	}
	 %>
"></input></td></tr>
<tr><td>Ghi chu<input type="text" name="txtgc" id="txtgc" class="canhphai" value="<%
		if(model!=null){
			out.println(model.getGHICHU());
		}
		if (updateModel != null) {
			out.println(updateModel.getGHICHU());
	}
	 %>
"></input></td></tr>
<tr><td align="center">
	<input type="submit" name="sub" value="Insert" <%
		if (updateModel != null) {
			out.println("disabled");
		}
	 %>></input>
	<input type="button" onclick="updateThanhVien();" name="update" value="Update" <%
		if (updateModel == null) {
			out.println("disabled");
		}
	 %> ></input>
</td></tr>
</table>
<input type="hidden" name="actionType" id="actionType" value="addNew"></input>"
</form>
</body>
</html>
